﻿<views:MvxWpfView
    x:Class="Sidvall.WorkItemManager.UI.Wpf.Views.DashboardView"
    xmlns:views="clr-namespace:MvvmCross.Wpf.Views;assembly=MvvmCross.Wpf"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:vms="clr-namespace:Sidvall.WorkItemManager.UI.ViewModels;assembly=Sidvall.WorkItemManager.UI"
    xmlns:Controls="clr-namespace:Sidvall.WorkItemManager.UI.Wpf.Controls" 
    xmlns:Converters="clr-namespace:Sidvall.UI.Wpf.Converters;assembly=Sidvall.UI.Wpf" 
    mc:Ignorable="d" 
    d:DesignHeight="500" d:DesignWidth="600">

    <views:MvxWpfView.Resources>
        <Converters:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
        <Converters:BooleanToVisibilityConverter x:Key="NotBooleanToVisibilityConverter" Not="True"/>
    </views:MvxWpfView.Resources>

    <Grid d:DataContext="{d:DesignInstance IsDesignTimeCreatable=True, Type={x:Type vms:DashboardViewModel}}">
        <ScrollViewer>
            <Grid>
                <Grid.Background>
                    <SolidColorBrush Color="{DynamicResource {x:Static SystemColors.InactiveBorderColorKey}}"/>
                </Grid.Background>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="20" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="20" />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="100" />
                    <ColumnDefinition Width="50" />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="100" />
                    <ColumnDefinition />
                    <ColumnDefinition Width="20" />
                </Grid.ColumnDefinitions>

                <Controls:HeaderControl Grid.ColumnSpan="8" HeaderCaption="Dashboard" />

                <Label Grid.Row="2" Grid.Column="1" FontSize="14" FontWeight="Bold">Workers:</Label>
                <TextBlock Grid.Row="2" Grid.Column="2" FontSize="14" FontWeight="Bold" Text="{Binding OverView.WorkerCount}" VerticalAlignment="Center" />
                <Label Grid.Row="2" Grid.Column="4" FontSize="14" FontWeight="Bold">Executing:</Label>
                <TextBlock Grid.Row="2" Grid.Column="5" FontSize="14" FontWeight="Bold" Text="{Binding OverView.ExecutingWorkItemCount}" VerticalAlignment="Center" />

                <Label Grid.Row="3" Grid.Column="1" FontSize="14" FontWeight="Bold">Tasks:</Label>
                <TextBlock Grid.Row="3" Grid.Column="2" FontSize="14" FontWeight="Bold" Text="{Binding OverView.WorkItemCount}" VerticalAlignment="Center" />
                <Label Grid.Row="3" Grid.Column="4" FontSize="14" FontWeight="Bold">Last Updated:</Label>
                <TextBlock Grid.Row="3" Grid.Column="5" Grid.ColumnSpan="2" FontSize="14" FontWeight="Bold" Text="{Binding LastUpdated}" VerticalAlignment="Center" 
                           ToolTip="{Binding LastUpdatedException}" />

                <Label Grid.Row="4" Grid.Column="1" FontSize="14" FontWeight="Bold">5 Latest Executed Tasks:</Label>
                <DataGrid Grid.Row="5" Grid.Column="1" RowHeaderWidth="0"  Grid.ColumnSpan="6" ItemsSource="{Binding OverView.LastExecutedItems}" 
                          AutoGenerateColumns="False" CanUserReorderColumns="False" CanUserResizeColumns="False" CanUserResizeRows="False" 
                          CanUserSortColumns="False" SelectionMode="Single" CanUserAddRows="False" Background="#FFF0F0F0">
                    <DataGrid.Columns>
                        <DataGridTextColumn Header="Name" Width="*" Binding="{Binding Name}" IsReadOnly="True" />
                        <DataGridTextColumn Header="Result" Width="80" Binding="{Binding LastWorkItemResultId}" IsReadOnly="True" />
                        <DataGridTextColumn Header="Time" Width="Auto" Binding="{Binding LastExecutionEndTime}" IsReadOnly="True" />
                    </DataGrid.Columns>
                </DataGrid>

                <Label Grid.Row="6" Grid.Column="1" FontSize="14" FontWeight="Bold">5 Latest Failed Tasks:</Label>
                <DataGrid Grid.Row="7" Grid.Column="1" RowHeaderWidth="0" Grid.ColumnSpan="6" ItemsSource="{Binding OverView.LastFailedItems}" 
                          AutoGenerateColumns="False" CanUserReorderColumns="False" CanUserResizeColumns="False" CanUserResizeRows="False" 
                          CanUserSortColumns="False" SelectionMode="Single" CanUserAddRows="False" Background="#FFF0F0F0">
                    <DataGrid.Columns>
                        <DataGridTextColumn Header="Name" Width="*" Binding="{Binding Name}" IsReadOnly="True" />
                        <DataGridTextColumn Header="Result" Width="80" Binding="{Binding LastWorkItemResultId}" IsReadOnly="True" />
                        <DataGridTextColumn Header="Time" Width="Auto" Binding="{Binding LastExecutionEndTime}" IsReadOnly="True" />
                    </DataGrid.Columns>
                </DataGrid>

                <Label Grid.Row="8" Grid.Column="1" FontSize="14" FontWeight="Bold">10 Latest Messages:</Label>
                <DataGrid Grid.Row="9" Grid.Column="1" RowHeaderWidth="0" Grid.ColumnSpan="6" ItemsSource="{Binding OverView.LastMessageLogItems}" 
                          AutoGenerateColumns="False" CanUserReorderColumns="False" CanUserResizeColumns="False" CanUserResizeRows="False" 
                          CanUserSortColumns="False" SelectionMode="Single" CanUserAddRows="False" Background="#FFF0F0F0">
                    <DataGrid.Columns>
                        <DataGridTextColumn Header="Name" Binding="{Binding WorkItemName}" IsReadOnly="True" />
                        <DataGridTextColumn Header="Result" Binding="{Binding ResultTypeName}" IsReadOnly="True" />
                        <DataGridTextColumn Header="Message" Width="*" Binding="{Binding ResultMessage}" IsReadOnly="True" />
                        <DataGridTextColumn Header="Time" Width="Auto" Binding="{Binding ExecutionStartTime}" IsReadOnly="True" />
                    </DataGrid.Columns>
                </DataGrid>
            </Grid>
        </ScrollViewer>
    </Grid>
</views:MvxWpfView>
